package club.beidouqixing.base.response;

import net.sf.json.JSONObject;

/*** 公共响应类* */
public class ResponseUtil {

    private static final int CODE_SUCCESS = 200;

    private static final int CODE_FAIL = 500;

    private static final int CODE_ERROR = 500;

    private static final int CODE_NO_LOGIN = 300;

    public static String success() {

        return success("success",null);
    }

    public static String  success(String message) {

        return success(message,null);
    }

    public static String success(Object data) {

        return success("success",data);
    }

    public static String success(String message, Object data) {

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code",CODE_SUCCESS);
        jsonObject.put("msg",message);
        jsonObject.put("data",data);

        return jsonObject.toString();
    }

    public static String error() {

        return error("fail",null);
    }

    public static String error(String message) {

        return error(message,null);
    }

    public static String error(Object data) {

        return error("fail",data);
    }

    public static String error(String message, Object data) {

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code",CODE_ERROR);
        jsonObject.put("msg",message);
        jsonObject.put("data",data);

        return jsonObject.toString();
    }

    public static String badrequest() {

        return badrequest("no identifier arguments",null);
    }

    public static String badrequest(String message) {

        return badrequest(message,null);
    }

    public static String badrequest(Object data) {

        return badrequest("no identifier arguments",data);
    }
    public static String badrequest(String message, Object data) {

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code",CODE_FAIL);
        jsonObject.put("msg",message);
        jsonObject.put("data",data);

        return jsonObject.toString();
    }

    public static String noLogin(String message) {

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code",CODE_NO_LOGIN);
        jsonObject.put("msg",message);
        jsonObject.put("data",null);

        return jsonObject.toString();
    }

}
